package com.example.demo.config;


import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.example.demo.filter.JwtTokenFilter;
import com.example.demo.interceptor.BlacklistInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.concurrent.ConcurrentHashMap;

@Configuration
public class WebConfig  implements WebMvcConfigurer {
    @Autowired
    private JwtTokenFilter jwtTokenFilter;
    @Autowired
    private BlacklistInterceptor blacklistInterceptor;

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        // 获取MybatisPlus的拦截器链
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        // 添加分页拦截器PaginationInnerInterceptor，实现自动分页
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return mybatisPlusInterceptor;

    }

    @Bean
    public FilterRegistrationBean<JwtTokenFilter> jwtFilter() {
        FilterRegistrationBean<JwtTokenFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(jwtTokenFilter);
//        registrationBean.addUrlPatterns("/api/*"); // 根据需要设置过滤的URL模式
        return registrationBean;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(blacklistInterceptor).addPathPatterns("/**"); // 根据需要调整拦截路径
    }





}